package com.xh.demo.controller;

import com.xh.demo.commons.model.Result;
import com.xh.demo.model.table.User;
import com.xh.demo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;

@Slf4j
@RestController
@Api(tags = "用户相关-接口")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/user")
    @ApiOperation(value = "保存用户信息", notes = "555:系统未知异常")
    public Result<User> saveUser(@RequestBody User user) {
        User resultUser = userService.saveUser(user);
        log.info(resultUser.toString());
        return Result.success(resultUser);
    }

    @GetMapping("/user/{id}")
    @ApiOperation(value = "查询用户信息", notes = "555:系统未知异常")
    public Result<User> getUserById(@PathVariable("id") Long id) {
        User resultUser = userService.getUserById(id);
        return Result.success(resultUser);
    }

    @GetMapping("/sign/user/{id}")
    @ApiOperation(value = "查询用户信息", notes = "555:系统未知异常")
    public Result<User> getUserByIdSign(@PathVariable("id") Long id,
                                        @RequestHeader("accessKeyId") String accessKeyId,
                                        @RequestHeader("accessKeySecret") String accessKeySecret) {
        log.info("param: accessKeyId={} accessKeySecret={}", accessKeyId, accessKeySecret);
        User resultUser = userService.getUserById(id);
        return Result.success(resultUser);
    }

    @GetMapping("/timestamp/user/{id}")
    @ApiOperation(value = "查询用户信息", notes = "555:系统未知异常")
    public Result<User> getUserByIdTimestamp(@PathVariable("id") Long id,
                                             @RequestParam(value = "timestamp", required = false) String timestamp) {
        log.info("param: timestamp={}", timestamp);
        User resultUser = userService.getUserById(id);
        return Result.success(resultUser);
    }

    @GetMapping("/user")
    @ApiOperation(value = "查询用户信息", notes = "555:系统未知异常")
    public Result<User> getUserByIdV2(@RequestParam("id") Long id) {
        User resultUser = userService.getUserById(id);
        return Result.success(resultUser);
    }


}